In this step of the tutorial you create keyboard navigation between the Home, Media, Car, and application screens. You use triggers with JavaScript scripts to set which node receives the key input when the user presses a key on their keyboard.
The starting point of this tutorial is the Keyboard input.kzproj Kanzi Studio project file stored in <KanziWorkspace>/Tutorials/Keyboard input/Tool_project directory.
The <KanziWorkspace>/Examples/Keyboard input directory contains the completed project of this tutorial.
The starting point project contains the content you need to complete this tutorial:









In this section you create keyboard navigation for the toggle buttons you use to navigate between the Page nodes which show the screens of the application.
To use keyboard keys to navigate between Page nodes:

In the Node Components click Trigger Settings and in the Trigger Settings Editor click Add condition. The Trigger Condition Editor opens.
Trigger conditions enable you to set which conditions must be met for the trigger to set off. Here you set the Key Down trigger to be set off when the user presses a specific key on the keyboard. You set which key sets off the trigger in the next step of this section.

In the Trigger Condition Editor and the Trigger Settings Editor windows click Save.
With this condition when the user presses down the Right Arrow key, the Key Down trigger executes the actions you set in the trigger. For a list of the keyboard key codes used in Kanzi, see Keyboard input codes reference.


// Get the Home Page Host node. var homePage = node.lookupNode('#Home'); // The value of the Page.State property tells whether the Page or Page Host node is active: // - If the value is 0, the node is inactive and invisible. // - If the value is 1, the node is active and visible. var homeActive = homePage.getProperty('Page.State'); var mediaPage = node.lookupNode('#Media'); var mediaButton = node.lookupNode('#MediaButton'); var mediaActive = mediaPage.getProperty('Page.State'); var carPage = node.lookupNode('#Car'); var carButton = node.lookupNode('#CarButton'); var carActive = carPage.getProperty('Page.State'); var navigationPage = node.lookupNode('#Navigation'); var navigationButton = node.lookupNode('#NavigationButton'); var navigationActive = navigationPage.getProperty('Page.State') // Check which of the application Page nodes is active and navigate to the next application. if (homeActive == 1) { mediaPage.navigateToThisPage(); // Set the Toggle State for the button of the next application to 1. // Toggle State Controller Property controls the state of these toggle buttons. mediaButton.setProperty('ButtonConcept.ToggleState', 1); } else if (mediaActive == 1) { carPage.navigateToThisPage(); carButton.setProperty('ButtonConcept.ToggleState', 1); } else if (carActive == 1) { navigationPage.navigateToThisPage(); navigationButton.setProperty('ButtonConcept.ToggleState', 1); }
You use the script to set which Toggle Button node receives the keyboard input.
To try this out in the Kanzi Studio Preview, click the Preview window to set the focus to the window and press the Right Arrow key on your keyboard to navigate between the Home, Media, Car, and application screens. When each of the Page nodes is activated, the Toggle State of the Toggle Button which navigates to that Page is set to 1.


// Get the Home Page Host node. var homePage = node.lookupNode('#Home'); // Get the > Grid Layout 2D > HomeButton Button 2D node. var homeButton = node.lookupNode('#HomeButton'); // The value of the Page.State property tells whether the Page or Page Host node is active: // - If the value is 0, the node is inactive and invisible. // - If the value is 1, the node is active and visible. var homeActive = homePage.getProperty('Page.State'); var mediaPage = node.lookupNode('#Media'); var mediaButton = node.lookupNode('#MediaButton'); var mediaActive = mediaPage.getProperty('Page.State'); var carPage = node.lookupNode('#Car'); var carButton = node.lookupNode('#CarButton'); var carActive = carPage.getProperty('Page.State'); var navigationPage = node.lookupNode('#Navigation'); var navigationActive = navigationPage.getProperty('Page.State'); var mapPage = node.lookupNode('#Map'); var mapActive = mapPage.getProperty('Page.State'); // Check which of the application Page nodes is active and navigate to the next application. if (navigationActive == 1 && mapActive != 1) { carPage.navigateToThisPage(); // Set the Toggle State for the button of the next application to 1. // Toggle State Controller Property controls the state of these toggle buttons. carButton.setProperty('ButtonConcept.ToggleState', 1); } else if (carActive == 1) { mediaPage.navigateToThisPage(); mediaButton.setProperty('ButtonConcept.ToggleState', 1); } else if (mediaActive == 1) { homePage.navigateToThisPage(); homeButton.setProperty('ButtonConcept.ToggleState', 1); }
In this section you rename the scripts you created in this step of the tutorial and create folders for those scripts.
To organize the scripts files in your Kanzi Studio project:


In the Preview press the Left Arrow key to navigate left between the Home, Media, Car, and application screens. You can now use the Right Arrow and Left Arrow keys to navigate between application screens.
Tutorial: Create application flow with Page nodes
Using the Page and Page Host nodes
Keyboard input codes reference